define([
    'text!templates/pagebar.html',
    'jquery',
    'underscore',
    'backbone'
], function(template) {

    var PageBarView = Backbone.View.extend({
        el: $('.pagebar'),
        page: 0,
        
        initialize: function() {

        },
        render: function() {
            console.log("PageBarView.render()");
            var element = this.$el;
            var actualPageIdx = this.page;

            $.post("service/diariespages", function(pageCount) {
                if (pageCount < 0) {
                    pageCount = 0;
                }
                var compiledTemplate = _.template(template,
                        {
                            actualPage: actualPageIdx,
                            pageCount: pageCount
                        });
                element.html(compiledTemplate);
            });
        }
    });

    return PageBarView;
});


